#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

#include <sys/wait.h>

int main(){

    int rw_pipe[2];

    int pid;
    pipe(rw_pipe);

    pid = fork();

    if(pid < 0){

    } else if(pid == 0) {    // pid == 0  child process

        dup2(rw_pipe[1], 1);
        int s = 668;
        // write(rw_pipe[1], &s, sizeof(s));

        // fprintf(stdout, "%d", s);
        int nw = write(stdout, &s, sizeof(s));

        printf("C: %d\n", nw);
        exit(0);

    } else{    // pid > 0  parent process

        int s;
        int n = read(rw_pipe[0], &s, sizeof(s));


        printf("%d: s = %d\n",n, s);
        waitpid(pid, 0, 0);
    }
    return 0;
}
